package com.air.test;

import java.security.Security;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import com.air.ota.util.HexStringUtil;


public class MainClass {
	
	public static void main(String[] args) throws Exception {
	    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());        
	    byte[] input = HexStringUtil.hexStringToBytes("56D83A9C20202020");
	    byte[] keyBytes =HexStringUtil.hexStringToBytes("0111223344556677");

	    SecretKeySpec key = new SecretKeySpec(keyBytes, "DES");
	    Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
	    System.out.println("input : " + new String(input));
	    
	    // encryption pass
	    cipher.init(Cipher.ENCRYPT_MODE, key);
	   /* byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
	    int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
	    ctLength += cipher.doFinal(cipherText, ctLength);
	    System.out.println("cipher: " + HexStringUtil.bytesToHexString(cipherText) + " bytes: " + ctLength);
*/		
	    
	    byte[] encryptData =cipher.doFinal(input);
	    System.out.println("cipher: " + HexStringUtil.bytesToHexString(encryptData) );
	    // decryption pass
	    /*
	    cipher.init(Cipher.DECRYPT_MODE, key);
	    byte[] plainText = new byte[cipher.getOutputSize(ctLength)];
	    int ptLength = cipher.update(cipherText, 0, ctLength, plainText, 0);
	    ptLength += cipher.doFinal(plainText, ptLength);
	    System.out.println("plain : " + new String(plainText) + " bytes: " + ptLength);*/
	  }
	
}
